Skip to main content

Dockerizing a Javascript

Dockerizing a Javascript Project

So this is a basic example of a docker file

FROM node:16

COPY . ./

RUN npm install

CMD \["node","index.js"\]

Assuming this is our folder structure

|-index.js

|-package.JSON

|-dockerfile

Here is each line in the docker file:

  1. Set the base image to the node runtime

  2. Copy our project, into / in the image

  3. Run npm install to get dependencies

  4. The run command (which will be run when the image is run) is set to node index.js

Finally we can build and run it like so

docker build -t imagename . 

docker run imagename